<?php
namespace app\action\controller;

use think\Db;

class Common
{
    /**
     * 后台列表一键删除
     * */
    public function listDataAllDelete()
    {
        $input = Request()->param();

        $table = thinkDecrypt($input['param']);
        $check_ids = $input['check_ids'];

        if (empty($table)) apiReturn(2, '一键删除所需参数缺失，请联系后台开发人员');
        if (empty($check_ids)) apiReturn(2, '请勾选您需要删除的数据');

        $is_table = Db()->query('SHOW TABLES LIKE "' . config('database.prefix') . $table . '"');
        if ($is_table) {
            $res = Db::name($table)->where(['id' => ['IN', $check_ids]])->delete();
            if ($res) {
                apiReturn(1, '删除成功');
            } else {
                apiReturn(2, '删除失败或数据不存在');
            }
        } else {
            apiReturn(2, '数据表不存在');
        }
    }
}